Date.prototype.format = function (fmt) {
    let o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (let k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};

function toThousands(num) {
    let result = [], counter = 0;
    num = (num || 0).toString().split('');
    for (let i = num.length - 1; i >= 0; i--) {
        counter++;
        result.unshift(num[i]);
        if (!(counter % 3) && i != 0) {
            result.unshift(',');
        }
    }
    return result.join('');
}

//字符串转日期格式，strDate要转为日期格式的字符串
// alert(getDateFromStr("2016-06-14"));
function getDateFromStr(strDate) {
    let date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
        function (a) {
            return parseInt(a, 10) - 1;
        }).match(/\d+/g) + ')');
    return date;
}

//字符串转日期格式，strDate要转为日期格式的字符串
// alert(getDateTimeFromStr("2016-6-14 11:20:00"));
function getDateTimeFromStr(strDate) {
    let str = strDate;
    let a = str.split(" ");
    let b = a[0].split("-");
    let c = a[1].split(":");
    let date = new Date(b[0], b[1], b[2], c[0], c[1], c[2]);
    return date;
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return null;
}

Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};

Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

//处理js number精度越界,越界字段转成String展示
function getRealJsonData(baseStr) {
    if (!baseStr || typeof baseStr != 'string') return;
    var jsonData = null;
    try {
        jsonData = JSON.parse(baseStr);
    } catch (err){
        return null;
    }
    var needReplaceStrs = [];
    loopFindArrOrObj(jsonData,needReplaceStrs);
    needReplaceStrs.forEach(function (replaceInfo) {
        var matchArr = baseStr.match(eval('/"'+ replaceInfo.key + '":[0-9]{15,}/'));
        if (matchArr) {
            var str = matchArr[0];
            var replaceStr = str.replace('"' + replaceInfo.key + '":','"' + replaceInfo.key + '":"');
            replaceStr += '"';
            baseStr = baseStr.replace(str,replaceStr);
        }
    });
    var returnJson = null;
    try {
        returnJson = JSON.parse(baseStr);
    }catch (err){
        return null;
    }
    return returnJson;
}

//遍历对象类型的
function getNeedRpStrByObj(obj,needReplaceStrs) {
    for (var key in obj) {
        var value = obj[key];
        if (typeof value == 'number' && value > 9007199254740992){
            needReplaceStrs.push({key:key});
        }
        loopFindArrOrObj(value,needReplaceStrs);
    }
}

//遍历数组类型的
function getNeedRpStrByArr(arr,needReplaceStrs) {
    for(var i=0; i<arr.length; i++){
        var value = arr[i];
        loopFindArrOrObj(value,needReplaceStrs);
    }
}

//递归遍历
function loopFindArrOrObj(value,needRpStrArr) {
    var valueTypeof = Object.prototype.toString.call(value);
    if (valueTypeof == '[object Object]') {
        needRpStrArr.concat(getNeedRpStrByObj(value,needRpStrArr));
    }
    if (valueTypeof == '[object Array]') {
        needRpStrArr.concat(getNeedRpStrByArr(value,needRpStrArr));
    }
}

// 默认时间范围
let now = new Date();
let beginDate = new Date(now.getTime() - 3 * 30 * 24 * 3600 * 1000);
let min = beginDate.format("yyyy-MM-dd hh:mm:ss");
let max = now.format("yyyy-MM-dd hh:mm:ss");
let defaultDateValue = min + ' - ' + max;